<?php

namespace app\api\controller;

use app\admin\model\jskmsg\Companyname;
use app\api\model\ArticleModel;
use app\api\model\BaseModel;
use app\api\model\CategoryModel;
use app\api\model\ConfigModel;
use app\api\model\GoodsModel;
use app\api\model\RotationChartImgsModel;
use app\api\service\JsonService;
use app\common\controller\Api;
use wx\WxMessage;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['index','config'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        $redbag = ConfigModel::all();
        return JsonService::successful($redbag);
       
    }


    //获取配置接口值
    public function config()
    {
        $params = $this->request->param();
        if (empty($params['name'])) {
            return JsonService::fail('参数错误');
        }
        $params['name'] = str_replace('，', ',', $params['name']);
        $params['name'] = explode(',', $params['name']);
        $value = [];
        foreach ($params['name'] as $param) {
            $value[$param] = ConfigModel::getValue($param, 'basic');
            if (stripos($param, 'image') !== false) {
                $value[$param] = BaseModel::siteUrl() . $value[$param];
            }
        }
        return JsonService::successful(compact('value'));
    }

    //文章列表接口
    public function articleList()
    {
        $list =  new ArticleModel();
        $params = $this->request->param();
        if(!empty($params['title'])){
            $list = $list->where('title','like',"%{$params['title']}%");
        }
        $list = $list->select();
        return JsonService::successful($list);
    }

    //文章详情接口
    public function articleDetail()
    {
        $params = $this->request->param();
        if (empty($params['id'])) {
            return JsonService::fail('参数错误');
        }
        $list = ArticleModel::detail($params['id']);
        return JsonService::successful($list);
    }

    public function companyList()
    {
        return JsonService::successful(Companyname::select());
    }
    
    //轮播图接口
    public function carousel()
    {
        $list = RotationChartImgsModel::lst();
        return JsonService::successful($list);
    }


}
